package com.boang.controller;

import com.boang.domain.po.Users;
import com.boang.domain.vo.UsersVO;
import com.boang.resp.Result;
import com.boang.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.Objects;

/*
  @author: 13813
  @date: 2024/9/6 10:52
*/
@RestController
public class LoginController {

    @Autowired
    private UsersService usersService;

    @PostMapping("/login/username-pwd")
    public Result<String> loginWithUsernameAndPassword(@RequestBody UsersVO usersVO) {
        try {
            String token = usersService.loginWithUsernameAndPassword(usersVO);
            return Result.ok(token);
        } catch (Exception e) {
            return Result.failed("登录失败");
        }
    }

    @PostMapping("/login/verification-code")
    public Result<String> loginWithVerificationCode(@RequestBody UsersVO usersVO) {
        try {
            String token = usersService.loginWithVerificationCode(usersVO);
            return Result.ok(token);
        } catch (Exception e) {
            return Result.failed("登录失败");
        }
    }
}
